package thread.threaddemo;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/01/21:25
 * @Description:
 */
public class ThreadDemo9 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        FutureTask<String> futureTask=new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                //具体的业务代码
               String[] arrs=new String[]{"java","mysql","sql"};
               String random =arrs[new Random().nextInt(3)];
               System.out.println(Thread.currentThread().getName()+"随机字符串为"+random);
               return random;
            }
        });
        Thread thread=new Thread(futureTask);
        //启动
        thread.start();
        String  result=futureTask.get();
        System.out.println(Thread.currentThread().getName()+"随机字符串结果为"+result);
    }
}
